unit uniManFaca;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uniManPadrao, DB, ADODB, Grids, DBGrids, StdCtrls, ExtCtrls,
  Buttons;

type
  TfrmManFaca = class(TfrmManPadrao)
    procedure btnPesquisaClick(Sender: TObject);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnEditarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    procedure p_Select(pParametros:String);
  public
    { Public declarations }
  end;

var
  frmManFaca: TfrmManFaca;

implementation

uses uniCadFaca;

{$R *.dfm}

{ TfrmManFaca }

procedure TfrmManFaca.p_Select(pParametros: String);
var sSQL : String;
begin
  sSQL := ' SELECT * FROM TB_FACA '+
          ' WHERE 1=1 ';
  sSQL := sSQL + pParametros;
  QR_Grid.Close;
  QR_Grid.SQL.Clear;
  QR_Grid.SQL.Add(sSQL);
  QR_Grid.Open;
end;

procedure TfrmManFaca.btnPesquisaClick(Sender: TObject);
var sParametros : String;
begin
  inherited;
  if edtCodigo.Text <> '' then
    sParametros := sParametros + ' AND cd_faca  = '+edtCodigo.Text;

  if edtDescricao.Text <> '' then
    sParametros := sParametros + ' AND descricao LIKE '+QuotedStr(edtDescricao.Text);

  p_Select(sParametros);
end;

procedure TfrmManFaca.btnIncluirClick(Sender: TObject);
begin
 inherited;
   try
    Application.CreateForm(TfrmCadFaca, frmCadFaca);
    frmCadFaca.sEstado := 'I';
    frmCadFaca.sCdCampo := '';
    frmCadFaca.ShowModal;
  finally
    frmCadFaca.Free;
  end;
  p_Select('');
end;

procedure TfrmManFaca.btnEditarClick(Sender: TObject);
begin
 inherited;
   try
    Application.CreateForm(TfrmCadFaca, frmCadFaca);
    frmCadFaca.sEstado := 'E';
    frmCadFaca.sCdCampo := QR_Grid.FieldByName('cd_faca').AsString;
    frmCadFaca.ShowModal;
  finally
    frmCadFaca.Free;
  end;
  p_Select('');
end;

procedure TfrmManFaca.FormShow(Sender: TObject);
begin
  inherited;
   p_Select('');
end;

end.
